| Conditions | 6 |
| Total Lines | 26 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { AxiosRequestConfig } from 'axios'; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * If present it adds access token to Authorization header. |
||
| 13 | * |
||
| 14 | * @param config The axios request config |
||
| 15 | */ |
||
| 16 | public requestHandler(config: AxiosRequestConfig): Promise<AxiosRequestConfig> { |
||
| 17 | config = this.setAuthorizationHeader(config); |
||
| 18 | |||
| 19 | // Authorization header set so go ahead |
||
| 20 | if (config.headers?.Authorization) { |
||
| 21 | return Promise.resolve(config); |
||
| 22 | } |
||
| 23 | |||
| 24 | // trying client credentials auth so go ahead |
||
| 25 | if (config.url === '/auth' && config.data?.grant_type === GrantType.ClientCredentials) { |
||
| 26 | return Promise.resolve(config); |
||
| 27 | } |
||
| 28 | |||
| 29 | if (!this.beditaClient.getConfig('clientId')) { |
||
| 30 | return Promise.resolve(config); |
||
| 31 | } |
||
| 32 | |||
| 33 | return this.beditaClient |
||
| 34 | .clientCredentials() |
||
| 35 | .then(() => Promise.resolve(this.setAuthorizationHeader(config))); |
||
| 36 | } |
||
| 52 |